// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Start Message Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

// Aliases
private alias 7 : TYPE_STARTMESSAGE

private alias object.value0 : start.fadeValue
private alias object.value4 : start.demoCountdown

event ObjectMain
	switch object.state
	case 0
		CheckTouchRect(0, 0, screen.xsize, screen.ysize)
		if inputPress.start == 1
			checkResult = 1
		end if
		if inputPress.buttonA == 1
			checkResult = 1
		end if
		if inputPress.buttonB == 1
			checkResult = 1
		end if
		if inputPress.buttonC == 1
			checkResult = 1
		end if
		if checkResult > -1
			if options.stageSelectFlag == 1
				if checkResult > 0
					object.state = 2
				else
					object.state = 1
				end if
			else
				object.state = 1
			end if
			PlaySfx(SfxName[Menu Select], 0)
			StopMusic()
		else
			start.demoCountdown++
			if start.demoCountdown == 420
				object.state = 4
			end if
		end if
		break
	case 1
		start.fadeValue += 8
		if start.fadeValue == 320
			options.attractMode = 0
			player.lives = 3
			player.continues = 0
			player.score = 0
			player.scoreBonus = 0xC350
			starPostID = 0
			specialStage.listPos = 0
			specialStage.emeralds = 0
			specialStage.nextZone = 0
			stage.activeList = PRESENTATION_STAGE
			stage.listPos = 3
			LoadStage()
		end if
		SetScreenFade(0, 0, 0, start.fadeValue)
		break
	case 2
		start.fadeValue += 8
		if start.fadeValue == 320
			options.attractMode = 0
			player.lives = 3
			player.continues = 0
			player.score = 0
			player.scoreBonus = 0xC350
			starPostID = 0
			specialStage.listPos = 0
			specialStage.emeralds = 0
			specialStage.nextZone = 0
			stage.activeList = PRESENTATION_STAGE
			stage.listPos = 3
			LoadStage()
		end if
		SetScreenFade(0, 0, 0, start.fadeValue)
		break
	case 3
		start.fadeValue += 8
		if start.fadeValue == 320
			options.attractMode = 0
			stage.listPos = 4
			LoadStage()
		end if
		SetScreenFade(0, 0, 0, start.fadeValue)
		break
	case 4
		start.fadeValue += 8
		if start.fadeValue == 320
			player.lives = 3
			player.continues = 0
			player.score = 0
			player.scoreBonus = 0xC350
			starPostID = 0
			specialStage.listPos = 0
			specialStage.emeralds = 0
			specialStage.nextZone = 0
			stage.activeList = BONUS_STAGE
			stage.listPos = attract.stage
			stage.listPos <<= 1
			attract.stage++
			attract.stage &= 3
			options.attractMode = 1
			credits.screen = 0
			LoadStage()
		end if
		SetScreenFade(0, 0, 0, start.fadeValue)
		break
	end switch
end event


event ObjectDraw
	object.animationTimer++
	if object.animationTimer > 59
		object.animationTimer = 0
	end if
	if object.animationTimer > 29
		DrawSpriteScreenXY(0, screen.xcenter, object.ypos)
	end if
end event


event ObjectStartup
	LoadSpriteSheet("Title/Title.gif")
	switch engine.deviceType
	case 0
		SpriteFrame(-49, -1, 98, 9, 1, 380)
		break
	case 1
		SpriteFrame(-57, -1, 114, 9, 1, 390)
		break
	end switch
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
